package com.itheima.day13.thread.test9;

public class TicketMyRubbale implements Runnable {
    private int tickets = 1000;
    private Object obj = new Object();


    @Override
    public void run() {
        while (true) {
            synchronized (obj) {
                if (tickets > 0) {
                    try {
                        Thread.sleep(0);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    tickets--;
                    System.out.println(Thread.currentThread().getName() + " 正在买票，还剩 " + tickets + " 张票。");
                } else {
                    break;
                }
            }
        }
    }

}
